/**
 * 
 */
package com.lemote.service.impl;

import java.io.Serializable;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

import com.lemote.core.Page;
import com.lemote.core.PropertyFilter;
import com.lemote.orm.hibernate.HibernateDao;
import com.lemote.service.BaseService;

/**
 * @author wuhui
 * 
 *         下午12:02:08
 */
@Component
@Transactional
public abstract class BaseServiceImpl<T, PK extends Serializable, EntityDao extends HibernateDao<T, PK>>
		implements BaseService<T, PK> {


	protected EntityDao entityDao;
	
	
	@Override
	public List<T> getAll() {
		
		return entityDao.getAll();
	}

	@Override
	public void add(T t) {

		entityDao.save(t);
	}

	@Override
	public void delete(PK id) {
		entityDao.delete(id);
	}

	@Transactional(readOnly = true)
	@Override
	public T get(PK id) {

		return entityDao.get(id);
	}

	@Transactional(readOnly = true)
	@Override
	public Page<T> getAll(Page<T> page) {

		return entityDao.getAll(page);
	}

	@Transactional(readOnly = true)
	@Override
	public List<T> getList(List<PropertyFilter> filters) {

		return entityDao.find(filters);
	}

	@Transactional(readOnly = true)
	@Override
	public Page<T> search(Page<T> page, List<PropertyFilter> filters) {

		return entityDao.findPage(page, filters);
	}

	@Override
	public void update(T t) {

		entityDao.save(t);
	}

	@Override
	public void delete(List<PK> ids) {

		entityDao.delete(ids);
	}
	
	

	@Override
	public T get(String propertyName, Object value) {
		
		return entityDao.findUniqueBy(propertyName, value);
	}

	@Autowired
	public abstract void setEntityDao(EntityDao entityDao);

}
